//提现页面 0
//确定提现页面 1
//提交提现页面 2
//添加银行卡页面 3

define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');

var dialog=require('component-dialog');
	
var base=require('component-base');
	
var history=require('component-history');

require('component-page');
/**
 * 提现操作
 */
exports.init=function(m){
	history.addHis(this,arguments);//增加历史
    window.$ddf_withdraw = m;
	var htmlStr = "";
	
	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ ddf.index.index_js+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">提现</a></div></div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips0" ></div>';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-money"></i></span>';
	htmlStr += '<h5>账户</h5>';
	htmlStr += '</div>        ';
	htmlStr += '<div class="widget-content clearfix">';
	htmlStr += '<div class="fontsize">';
	htmlStr += '<span>账户余额：<span class="color_f90" id="show_balance"></span>元</span>';
	htmlStr += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	htmlStr += '<span>可提现余额：<span class="color_f90" id="show_minBalance"></span>元</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>   ';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-pencil"></i></span>';
	htmlStr += '<h5>操作</h5>';
	htmlStr += '</div>  ';
	htmlStr += '<div class="widget-content">';
	htmlStr += '<div class="div-btn">';
	htmlStr += '<button class="btn btn-success" type="button" onclick="$ddf_withdraw.bindingbankcardPage()">添加银行卡</button>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>提取余额到银行卡</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">';
	htmlStr += '<div class="control-group" id="control-group-amount">';
	htmlStr += '<label class="control-label">提现金额：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input type="text" id="input-amount" class="input_height"/>';
	htmlStr += ' <span class="help-inline" id="warning"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行账户：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_bankNumber_sort"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_bankName"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">账户姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_accountName"></span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" id="btnNext" type="button" onClick="$ddf_withdraw.nextStatus()">下一步</button>';
	htmlStr += '</div>';
	htmlStr += '</form> ';
	htmlStr += '</div>  ';
	htmlStr += '</div> ';
               
	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	showDiv("content0");
	
	$("#content0").html(htmlStr); //在页面上显示
	
	
	
	
	$("#input-amount").change(function() {
			
			var amount=$("#input-amount").val();
			var minBalance=$("#show_minBalance").html();
			
			if(isNull(amount)|| !isNumber2Decimal(amount)){
				$("#warning").removeClass("help-inline");
				$("#warning").html(""); 
				clearErrorMessage("control-group-amount");
				addErrorMessage("control-group-amount","input-amount","提现金额非法");
				
			}else{
				if(parseFloat(amount) > parseFloat(minBalance)){
					$("#warning").removeClass("help-inline");
					$("#warning").html("");
					clearErrorMessage("control-group-amount");
					addErrorMessage("control-group-amount","input-amount","余额不足");
				}else if(withDraw["min"] >0 && parseFloat(amount) < withDraw["min"]){
					$("#warning").removeClass("help-inline");
					$("#warning").html("");
					clearErrorMessage("control-group-amount");
					addErrorMessage("control-group-amount","input-amount","最低提现金额"+withDraw["min"]);
				}else{
					withDraw["amount"]=$("#input-amount").val();
					clearErrorMessage("control-group-amount");
					$("#warning").addClass("help-inline");
					$("#warning").html(warmTips);
				}
			}
		});
	
	getWithdraw(); //获取用户的基本信息
	
	
};



/**
 * 提现数据
 */
function getWithdraw(){
	

	base.showLoading();
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.withdraw.getwithdraw,""));
		
		getWithDrawCallBack(data);
		
	}))().start();
	
}

/**
 * 提现数据的回调函数
 * @param data
 */
var withDraw={};//提现传递参数
var warmTips="";//警告提示文字
function getWithDrawCallBack(data){
	if(data["code"] == 1){
		
		$("#show_balance").html(parseFloat(data["balance"]));
		$("#show_minBalance").html(parseFloat(data["settleAmount"]));
		$("#show_bankName").html(data["bankName"]);
		$("#show_bankNumber_sort").html(data["bankNumber_sort"]);
		$("#show_accountName").html(data["accountName"]);
		
    	 $("#warning").html(data["tips"]);
    	 warmTips= $("#warning").html();
    	
    	withDraw["min"]=parseFloat(data["min"]);
		withDraw["balance"]=parseFloat(data["balance"]);
		withDraw["accountId"]=data["accountId"];
		withDraw["bankNumber"]=data["bankNumber"];
		withDraw["accountName"]=data["accountName"];
		withDraw["bankNumber_sort"]=data["bankNumber_sort"];
		withDraw["bankName"]=data["bankName"];
		
		$("#btnNext").attr("disabled", false);
	}else{
		//SHOP-30
		if(typeof(data.balance) != "undefined"){
			$("#show_balance").html(parseFloat(data["balance"]));
			$("#show_minBalance").html(parseFloat(data["settleAmount"]));
		}
		$("#btnNext").attr("disabled", true);
		base.tips_error(data["message"]);
	}
	

	base.cancelLoading();
}



function nextStatus(){
		
		var amount=$("#input-amount").val();
		var minBalance=$("#show_minBalance").html();
		
		
		if(isNull(amount)|| !isNumber2Decimal(amount) || amount<=0){
			$("#warning").removeClass("help-inline");
			$("#warning").html(""); 
			clearErrorMessage("control-group-amount");
			addErrorMessage("control-group-amount","input-amount","提现金额非法");
			
		}else{
			if(parseFloat(amount) > parseFloat(minBalance)){
				$("#warning").removeClass("help-inline");
				$("#warning").html("");
				clearErrorMessage("control-group-amount");
				addErrorMessage("control-group-amount","input-amount","余额不足");
			}else if(withDraw["min"] >0 && parseFloat(amount) < withDraw["min"]){
				$("#warning").removeClass("help-inline");
				$("#warning").html("");
				clearErrorMessage("control-group-amount");
				addErrorMessage("control-group-amount","input-amount","最低提现金额"+withDraw["min"]);
			}else{
				withDraw["amount"]=$("#input-amount").val();
				clearErrorMessage("control-group-amount");
				$("#warning").html(warmTips);
				confirmPage();
			}
			
		}
		
	
}


/**
 * 确认提现信息
 */
function confirmPage(){
	
	var htmlStr="";
	
	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ ddf.index.index_js+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:$ddf_withdraw.showDiv("content0") >提现</a><a href="javascript:void(0)" class="current">提现-确认提现信息</a></div></div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips1" ></div>';


	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>确认提现信息</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">';
	htmlStr += '<div class="control-group" id="control-group-amount">';
	htmlStr += '<label class="control-label">提现金额：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show-amount-confirm">'+withDraw["amount"]+'  &nbsp;&nbsp; 元</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行账户：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_bankNumber_sort_confirm">'+withDraw["bankNumber_sort"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_bankName-confirm">'+withDraw["bankName"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">账户姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_accountName-confirm">'+withDraw["accountName"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-payPassword">';
	htmlStr += '<label class="control-label">支付密码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input type="password" id="payPassword" />';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="form-actions">';
	htmlStr += ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	htmlStr += '<button class="btn btn-primary" type="button" onClick=$ddf_withdraw.showDiv("content0")>返回上一步</button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_withdraw.confirm()">确认提现</button>';
	htmlStr += '</div>';
	htmlStr += '</form> ';
	htmlStr += '</div>  ';
	htmlStr += '</div> ';
               
	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	showDiv("content1")
	
	$("#content1").html(htmlStr); 
	
	
	$("#payPassword").change(function() {

		var payPassword=$("#payPassword").val();
		if(isNull(payPassword)){
			addErrorMessage("control-group-payPassword","payPassword","支付密码不能为空");
		}else if(!isPayPassword(payPassword)){
			addErrorMessage("control-group-payPassword","payPassword","支付密码为6位数字，请重新输入!");
		}else{
			clearErrorMessage("control-group-payPassword");
		}

	});
	
}

/**
 * 提交提现要求
 */
function confirm(){
	
	var payPassword=$("#payPassword").val();
	if(isNull(payPassword)){
		addErrorMessage("control-group-payPassword","payPassword","支付密码不能为空");
		return;
	}else if(!isPayPassword(payPassword)){
		addErrorMessage("control-group-payPassword","payPassword","支付密码为6位数字，请重新输入!");
		return;
	}else{
		clearErrorMessage("control-group-payPassword");
		payPassword=MD5($("#payPassword").val());
	}
	
		_sign_key=MD5(
				 withDraw["accountId"]
				+withDraw["amount"]
				+withDraw["bankNumber"]
				+withDraw["bankName"]
				+withDraw["accountName"]
				+payPassword
			);
		
		
		var params={
				
				"accountId":withDraw["accountId"],
				"bankNumber":withDraw["bankNumber"],
				"bankName":withDraw["bankName"],
				"accountName":withDraw["accountName"],
				"amount":withDraw["amount"],
				"paypwd":payPassword,
				"_sign_key":_sign_key
				
		};
		
		
		base.showLoading();
		
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.withdraw.addwithdraw,params));
			
			addwithdrawCallBack(data);
			
		}))().start();
	
}


function addwithdrawCallBack(data){
	
	if(data["code"]==1){
		
		withdrawResultPage();
		
	}else{
		
		base.tips_error(data["message"]);
		
    }
	
	base.cancelLoading();
}




function withdrawResultPage(){
var htmlStr="";
	
	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ ddf.index.index_js+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_withdraw.showDiv("content0") >提现</a><a href="javascript:void(0)" class="current">提现-提现结果</a></div></div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips2" ></div>';

	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-pencil"></i></span>';
	htmlStr += '<h5>操作</h5>';
	htmlStr += '</div>  ';
	htmlStr += '<div class="widget-content">';
	htmlStr += '<div class="div-btn">';
	htmlStr += '<button class="btn btn-success" type="button" onclick=$ddf_withdraw.queryWithdrawSettle()>查看提现记录</button>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';

	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>提现结果</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">';
	htmlStr += '<div class="control-group" id="control-group-amount">';
	htmlStr += '<label class="control-label">提现金额：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show-amount-confirm">'+withDraw["amount"]+'  &nbsp;&nbsp; 元</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行账户：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_bankNumber_sort_confirm">'+withDraw["bankNumber_sort"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">银行名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_bankName-confirm">'+withDraw["bankName"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">账户姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="show_accountName-confirm">'+withDraw["accountName"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	htmlStr += '</form> ';
	htmlStr += '</div>  ';
	htmlStr += '</div> ';
               
	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	showDiv("content2");

	
	$("#content2").html(htmlStr); 
}

//自动跳到提现记录页面
function queryWithdrawSettle(){
	
	
	$("#withdrawSettleSpan").click();
	
}


/**
 * 打开绑定银行卡页面
 */
function bindingbankcardPage(){
	history.addHis(this,arguments);//增加历史
	var htmlStr="";
	
	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:$ddf_withdraw.showDiv("content0")>银行帐号管理</a><a href="javascript:void(0)" class="current">银行卡绑定</a></div></div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips3" ></div>';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>绑定银行卡</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">	   ';
	
	htmlStr += '<div class="control-group" id="control-group-bankId" >';
	htmlStr += '<label class="control-label">银行卡开户行：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4 alert_w"  id="input-bankCard" type="text" value="请选择银行卡开户行" readonly onclick="$ddf_withdraw.openBankCardDialog()" />';
	htmlStr += '</div>';
	htmlStr += '</div>';
	/*
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">账户类型：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="account_type_name">银行卡</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
	htmlStr += '<li><a href=javascript:$ddf_withdraw.setAccountType("00","银行卡")>银行卡</a></li>';
	htmlStr += '<li><a href=javascript:$ddf_withdraw.setAccountType("01","银行存折")>银行存折</a></li>';
	htmlStr += '</ul></div> ';
	htmlStr += '</div>    ';
	htmlStr += '</div>';
	*/
	htmlStr += '<div class="control-group" id="control-group-bankNumber">';
	htmlStr += '<label class="control-label">银行卡号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4" type="text" id="input-bankNumber" value="">';
	htmlStr += '</div>              ';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group" id="control-group-accountName">';
	htmlStr += '<label class="control-label">持卡人姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4" type="text" id="input-accountName" value="">';
	htmlStr += '</div>              ';
	htmlStr += '</div>';
	/*
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">证件类型：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="btn-group">';
	htmlStr += '<button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="card_type_name">身份证</span>&nbsp;&nbsp;<span class="caret"></span></button>';
	htmlStr += '<ul class="dropdown-menu">';
	htmlStr += '<li><a href=javascript:$ddf_withdraw.setCardType(1,"身份证")>身份证</a></li>';
	htmlStr += '<li><a href=javascript:$ddf_withdraw.setCardType(2,"军人证")>军人证</a></li>';
	htmlStr += '<li><a href=javascript:$ddf_withdraw.setCardType(3,"户口本")>户口本</a></li>';
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-identity">';
	htmlStr += '<label class="control-label">证件号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4" type="text" id="input-identity" value="">';
	htmlStr += '</div>       ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-mobile">';
	htmlStr += '<label class="control-label">手机号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4" type="text" id="input-mobile">       ';
	htmlStr += '</div>                    ';
	htmlStr += '</div>';
	*/
	htmlStr += '<div class="control-group" >';
	htmlStr += '<label class="control-label"></label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input style="position: relative; top: 3px; z-index: 50;" id="defaultAcountCB" type="checkbox" value="true" checked="checked" onClick="$ddf_withdraw.setDefaultAcount()" />设为默认结算账户';
	htmlStr += '</div>             ';
	htmlStr += '</div>';
	/*
	htmlStr += '<div class="control-group" >';
	htmlStr += '<label class="control-label"></label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input style="position: relative; top: 3px; z-index: 50;"name="redisabledCB" id="redisabledCB" type="checkbox"onclick="$ddf_withdraw.redisabled()" onChange="$ddf_withdraw.redisabled()" /> 同意&nbsp;&nbsp;快捷支付服务协议&nbsp;&nbsp;，下次可凭卡号后4位快速付款';
	htmlStr += '</div>                  ';
	htmlStr += '</div>';
	*/
	
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" id="btnBindBankCard" type="button" onclick="$ddf_withdraw.bindBankCard()" >绑定</button> ';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_withdraw.showDiv("content0")>返回</button>  ';
	htmlStr += '</div>  ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	
	
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';

	showDiv("content3");

	$("#content3").html(htmlStr);
	
	setRadioStyle();
	
	
	$("#input-bankNumber").change(function() {
		var bankNumber=$("#input-bankNumber").val();

		if(isNull(bankNumber)){
			addErrorMessage("control-group-bankNumber","input-bankNumber","银行卡号非法");
		}else{
			if(accountTypeId=="00"){
				if(!isBankNumber(bankNumber)){
					addErrorMessage("control-group-bankNumber","input-bankNumber","卡号非法,必须为16-20位数字");
				}else{
					clearErrorMessage("control-group-bankNumber");
				}
			}else{
				clearErrorMessage("control-group-bankNumber");
			}
			
		}

	});
	
	$("#input-accountName").change(function() {

		var accountName=$("#input-accountName").val();

		if(isNull(accountName)){
			addErrorMessage("control-group-accountName","input-accountName","持卡人姓名非法");
		}else{
			clearErrorMessage("control-group-accountName");
		}

	});
	
	/*
	$("#input-identity").change(function() {
		
		var identity=$("#input-identity").val();
		if(isNull(identity)){
			addErrorMessage("control-group-identity","input-identity","证件号码不能为空");
		}else if(isLength(identity,50)){
			addErrorMessage("control-group-identity","input-identity","证件号码长度不能大于50字节");
		}else{
			if(identifyTypeId==1){
				if(!isIdCard(identity)){
					addErrorMessage("control-group-identity","input-identity","身份证号非法");
				}else{
					clearErrorMessage("control-group-identity");
				}
			}else if(identifyTypeId==2){
				if(!isJgCard(identity)){
					addErrorMessage("control-group-identity","input-identity","军人证号非法");
				}else{
					clearErrorMessage("control-group-identity");
				}
			}else{
				clearErrorMessage("control-group-identity");
			}
		}
		
	});
	
	$("#input-mobile").change(function() {
		
		var mobile=$("#input-mobile").val();
		
		if(!isMobile(mobile)){
			addErrorMessage("control-group-mobile","input-mobile","手机号码非法");
		}else{
			clearErrorMessage("control-group-mobile");
		}
		
	});
	*/
}



/**
 * 绑定银行卡
 */
function bindBankCard(){
	
	var bankNumber=$("#input-bankNumber").val();
	var accountName=$("#input-accountName").val();
	//var identity=$("#input-identity").val();
	//var mobile=$("#input-mobile").val();
	
	
	if(bankId=="-1" || bankId==""){
		addErrorMessage("control-group-bankId","input-bankCard","请选择银行");
		return;
	}
	
	if(isNull(bankNumber)){
		addErrorMessage("control-group-bankNumber","input-bankNumber","银行卡号非法");
		return;
	}else if(accountTypeId=="00"){
		if(!isBankNumber(bankNumber)){
			addErrorMessage("control-group-bankNumber","input-bankNumber","卡号非法,必须为16-20位数字");
			return;
		}
	}
	
	if(isNull(accountName)){
		addErrorMessage("control-group-accountName","input-accountName","持卡人姓名非法");
		return;
	}
	/*
	if(isNull(identity)){
		addErrorMessage("control-group-identity","input-identity","证件号码不能为空");
		return;
	}else if(isLength(identity,50)){
		addErrorMessage("control-group-identity","input-identity","证件号码长度不能大于50字节");
		return;
	}else{
		if(identifyTypeId==1){
			if(!isIdCard(identity)){
				addErrorMessage("control-group-identity","input-identity","身份证号非法");
				return;
			}else{
				clearErrorMessage("control-group-identity");
			}
		}else if(identifyTypeId==2){
			if(!isJgCard(identity)){
				addErrorMessage("control-group-identity","input-identity","军人证号非法");
				return;
			}else{
				clearErrorMessage("control-group-identity");
			}
		}else{
			clearErrorMessage("control-group-identity");
		}
	}
	
	if(!isMobile(mobile)){
		addErrorMessage("control-group-mobile","input-mobile","手机号码非法");
		return;
	}
	*/
	
	var params={
			
			"sgAccounts.accountName":accountName,
			"sgAccounts.bankId":bankId,
			"sgAccounts.bankNumber":bankNumber,
			//"sgAccounts.identifyTypeId":identifyTypeId,
			//"sgAccounts.identity":identity,
			//"sgAccounts.mobile":mobile,
			//"sgAccounts.accountType":accountTypeId,
			"defaultaccount":defaultAcount
			
	        };
	
	
	base.showLoading();

	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.bank.bindBankCard,params));
		
		bindBankCardCallBack(data);
		
	}))().start();
}

/**
 * 绑定银行卡_回调函数
 * @param data
 */
function bindBankCardCallBack(data){
	
	if(data["code"]==1){
		base.tips("添加银行卡成功");
		showDiv("content0");
		getWithdraw();
	}else{
		 base.tips_error(data["message"]);
	}
	
	base.cancelLoading();
}


/**
 * 选择证件类型
 */
var identifyTypeId="1";

function setCardType(type,name){
	
	
	identifyTypeId=type;
	
	$("#card_type_name").html(name);
	
}


/**
 * 选择账户类型
 */
var accountTypeId="00";

function setAccountType(id,name){
	
	accountTypeId=id;
	
	$("#account_type_name").html(name);
	
}

/**
 * 选择银行
 */
var bankId;
function setBank(_bankId){
	
	bankId=_bankId;
	
}


/**
 * 设置是否选择默认
 */
var defaultAcount="true";
function setDefaultAcount() {
	if ($("#defaultAcountCB").is(":checked")) {
		defaultAcount="true";
	}else{
		defaultAcount="false";
	}
}

/**
 * 是否已读条款
 */
function redisabled() {
	if ($("#redisabledCB").is(":checked")) {
		$("#btnBindBankCard").attr("disabled", false);
	} else {
		$("#btnBindBankCard").attr("disabled", true);
	}
}


/**
 * 打开银行列表
 */
exports.openBankCardDialog=function(){

	dialog.ddf_dialog_bank($("#input-bankCard"),function(id,name){  
		
		$("#input-bankCard").val(name);
		
		setBank(id);

		
    });
	
};


/**
 * 显示DIV
 */
function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
	if(block=="content0"){
		shopTypeId="";
	}
	

	
}





//暴露方法
exports.getWithdraw=getWithdraw;
exports.nextStatus=nextStatus;
exports.confirmPage=confirmPage;
exports.confirm=confirm;
exports.withdrawResultPage=withdrawResultPage;
exports.queryWithdrawSettle=queryWithdrawSettle;
exports.bindingbankcardPage=bindingbankcardPage;
exports.bindBankCard=bindBankCard;
exports.setCardType=setCardType;
exports.setAccountType=setAccountType;
exports.setDefaultAcount=setDefaultAcount;
exports.redisabled=redisabled;

exports.showDiv=showDiv;

});




